package com.jy.appmarket.screenlock.widget.dialog;

import com.jy.appmarket.R;

import android.app.Dialog;
import android.content.Context;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

//import com.appssuper.toolbox.R;

/**
 * 类说明：
 * 
 * @author xinhui.cheng
 * @date 2014-12-11
 * @version 1.0
 */
public class CustomDialog extends Dialog implements android.view.View.OnClickListener {

	private TextView mTitleTv;
	private TextView mContentTv;
	private Button mCancelBtn;
	private Button mConfirmBtn;
	private View mBtnLineView;

	private CustomDialogListener mListener;

	public interface CustomDialogListener {
		void onConfirm();
	}

	public CustomDialog(Context context) {
		super(context, R.style.custom_dialog_theme);
		init();
	}

	private void init() {
		setContentView(R.layout.custom_dialog);
		mTitleTv = findViewById(R.id.custom_dialog_title_tv);
		mContentTv = findViewById(R.id.custom_dialog_content_tv);
		mCancelBtn = findViewById(R.id.custom_dialog_cancel_btn);
		mConfirmBtn = findViewById(R.id.custom_dialog_confirm_btn);
		mBtnLineView = findViewById(R.id.btn_line);
		mCancelBtn.setOnClickListener(this);
		mConfirmBtn.setOnClickListener(this);
	}

	public CustomDialog setTitle(String title) {
		mTitleTv.setText(title);
		return this;
	}

	public CustomDialog setContent(String content) {
		mContentTv.setText(content);
		mContentTv.setVisibility(View.VISIBLE);
		return this;
	}
	
	public CustomDialog setConfirmBtnText(String text) {
		mConfirmBtn.setText(text);
		return this;
	}

	public CustomDialog setCancelBtnText(String text) {
		mCancelBtn.setText(text);
		return this;
	}

	public CustomDialog setListener(CustomDialogListener l) {
		mListener = l;
		return this;
	}
	
	public CustomDialog setConfirmDialogOnly(){
		mCancelBtn.setVisibility(View.GONE);
		mBtnLineView.setVisibility(View.GONE);
		mConfirmBtn.setBackgroundResource(R.drawable.dialog_btn_bg_confirm_selector);
		return this;
	}

	@Override
	public void onClick(View v) {
		switch (v.getId()) {
		case R.id.custom_dialog_cancel_btn:
			dismiss();
			break;
		case R.id.custom_dialog_confirm_btn:
			if (mListener != null) {
				mListener.onConfirm();
			}
			dismiss();
			break;
		}
	}

}
